package com.sparrow.mvc.ui;

@SuppressWarnings("serial")
public class JTextArea extends JWebBodyControl {

	private String rows;
	private String cols;
	private String readonly;
	private String disabled;
	private String tabIndex;

	public String getTabIndex() {
		Object requestTabIndex = this.pageContext.getRequest().getAttribute(
				this.getId() + ".tabIndex");
		if (requestTabIndex != null) {
			return String.format(" tabindex=\"%1$s\" ", requestTabIndex);
		} else if (this.tabIndex != null && this.tabIndex.trim() != "") {
			return String.format(" tabindex=\"%1$s\" ", this.tabIndex);
		} else {
			return "";
		}
	}

	public void setTabIndex(String tabIndex) {
		this.tabIndex = tabIndex;
	}

	public String getReadonly() {
		return readonly;
	}

	public void setReadonly(String readonly) {
		this.readonly = readonly;
	}

	public String getDisabled() {
		return disabled;
	}

	public void setDisabled(String disabled) {
		this.disabled = disabled;
	}

	public String getRows() {
		return rows;
	}

	public void setRows(String rows) {
		this.rows = rows;
	}

	public String getCols() {
		return cols;
	}

	public void setCols(String cols) {
		this.cols = cols;
	}

	@Override
	public String setTagNameAndGetTagAttributes() {
		super.setTagName("textarea");
		StringBuffer attributes = new StringBuffer();
		if (this.getCols() != null && this.getCols().toString().trim() != "") {
			attributes.append(String.format(" cols='%1$s' ", this.getCols()));
		}
		if (this.getRows() != null && this.getRows().toString().trim() != "") {
			attributes.append(String.format(" rows='%1$s' ", this.getRows()));
		}
		if (this.getReadonly() != null
				&& this.getReadonly().toString().trim() != "") {
			attributes.append(String.format(" readonly='%1$s' ", this
					.getReadonly()));
		}
		if (this.getDisabled() != null
				&& this.getDisabled().toString().trim() != "") {
			attributes.append(String.format(" disabled='%1$s' ", this
					.getDisabled()));
		}
		if (this.getTabIndex() != null
				&& this.getTabIndex().toString().trim() != "") {
			attributes.append(this.getTabIndex());
		}
		return attributes.toString();
	}

}
